# -*- coding: utf-8 -*-
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

mx_eyelink_get_tracker_version = binder_py('mx_eyelink_get_tracker_version')
mx_eyelink_get_tracker_version.mx_c.headers = ['<eyelink.h>','"mex.h"']
mx_eyelink_get_tracker_version.mx_c.code = '''

INT16 _main( char FARTYPE *ops )
{
    return eyelink_get_tracker_version( ops ); 
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    /* Buffer size */
    int bs; 
    /* Matlab buffer: WARNING no protection against buffer over load */
    /* Eyelink char. To support compatibility.*/
    char FARTYPE elb[40];
    
    /* Verify input arguments. */
    if(nrhs > 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);    
    *status = (double ) _main( elb );
    plhs[0] = mxCreateString( elb );   
    return;   
}


'''

mx_eyelink_get_tracker_version.mx_c.mdoc = \
'''function [ status, code ] = mx_eyelink_get_tracker_version( )
%MX_EYE_LINK_GET_TRACKER_VERSION After connection, determines if the 
% connected tracker is an EyeLink I or II.
%
% Remarks:
% For the EyeLink II tracker, it can optionally retrieve the tracker software
% version.
% 
% Returns:
% 0 if not connected, 1 for EyeLink I, 2 for EyeLink II. This will be 
% "EYELINK I" or "EYELINK II x.xx", where "x.xx" is the software version.
%
'''
mx_eyelink_get_tracker_version.write_c()
mx_eyelink_get_tracker_version.write_m()
mx_eyelink_get_tracker_version.compile()
mx_eyelink_get_tracker_version.write_sh()

